#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

const int Maxsize = 100;
typedef int ElemType;
typedef struct
{
    ElemType data;
    int next;
}StaticTable[Maxsize];

class StaticList
{
    public:
        StaticList();
        ~StaticList() = default;
        void InitList();
        bool insertPos(int pos, ElemType e);
        bool deletePos(int pos, ElemType &e);
        bool isEmpty();
        void printList();
    private:
        StaticTable st;
};

StaticList::StaticList()
{
    memset(st, 0, sizeof(st));
    for (int i = 0; i < Maxsize - 1; i++)
    {
        st[i].next = -2;
    }
    InitList();
}

void StaticList::InitList()
{
    st[0].next = -1;
}

bool StaticList::isEmpty()
{
    return st[0].next == -1;
}

bool StaticList::insertPos(int pos, ElemType e)
{
    if (pos < 1 || pos > Maxsize - 1)
    {
        return false;
    }

    int p = 0;
    int j = 0;
    while (p != -1 && j < pos - 1)
    {
        p = st[p].next;
        j++;
    }

    if (p == -1)
    {
        return false;
    }

    int ipos;
    for (int i = 1; i < Maxsize - 1; i++)
    {
        if (st[i].next == -2)
        {
            ipos = i;
            break;
        }
    }

    st[ipos].data = e;
    st[ipos].next = st[p].next;
    st[p].next = ipos;
    return true;
}

bool StaticList::deletePos(int pos, ElemType &e)
{
    if (pos < 1 || pos > Maxsize - 1)
    {
        return false;
    }
    
    int p = 0;
    int j = 0;
    while (p != -1 && j < pos - 1)
    {
        p = st[p].next;
        j++;
    }
    if (p == -1)
    {
        return false;
    }

    int dpos = st[p].next;
    e = st[dpos].data;
    st[p].next = st[dpos].next;
    st[dpos].next = -2;
    return true;
}

void StaticList::printList()
{
    int p = 0;
    while (st[p].next != -1)
    {
        p = st[p].next;
        cout << st[p].data << " ";
    }
    cout << endl;
}

void menu()
{
    printf ("1. insertPos\n");
    printf ("2. deletePos\n");
    printf ("3. isEmpty\n");
    printf ("4. printList\n");
}

void start(char c, StaticList &sl)
{
    int pos;
    ElemType e;
    switch (c)
    {
        case '1':
            printf ("input pos and e:\n");
            scanf ("%d %d", &pos, &e);
            if (!sl.insertPos(pos, e))
            {
                printf ("error\n");
            }
            break;
        case '2':
            printf ("input pos:\n");
            scanf ("%d", &pos);
            if (sl.deletePos(pos, e))
            {
                printf ("delete e: %d\n", e);
            }
            break;
        case '3':
            if (sl.isEmpty())
            {
                printf ("empty\n");
            }
            break;
        case '4':
            sl.printList();
            break;
        default:
            menu();
            break;
    }
}
int main()
{
   StaticList sl;
   char c = ' ';
   while (c != 'q')
   {
       scanf ("%c", &c);
       start(c, sl);
   }

   return 0;
}